package Gui.Dialogs;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;

import Gui.GameFrame;
import Main.Defines;

public class EndTurnDialog extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4032431689432117637L;

	private void buildUIContents() {
		JButton ok = new JButton("OK");

		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
				GameFrame.getInstance().update();

			}
		});
		add(ok, BorderLayout.CENTER);
	}

	public EndTurnDialog() {
		super(GameFrame.getInstance(), String.format("Player %d Turn!", Defines
				.CP().getIDPrintable()), true);

		

		setLayout(new GridLayout(0, 1, 0, 10));
		setLocationRelativeTo(GameFrame.getInstance());
		buildUIContents();

		pack();
		// REFACTOR THIS! MAGIC NUMBER
		if(getTitle() != null){
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + 75; // MAGIC NUMBER, 75 is size of a "typical" window icon
			width = (int) Math.max(width*1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}

		setVisible(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}
}
